iconEuler Examples

Instable Solutions of Differential Equations

The following demonstrates a common problem of many numerical algorithms. Given exact data, they should deliver a specific solution. But due to rounding errors, the solution forks into a second solution.

As a first example, we consider the differential equation

Instable Solutions of Differential Equations

which looks harmless. Let us solve it for the initial values

Instable Solutions of Differential Equations

>function f(x,y) := [y[2],100*y[1]]
>x=0:0.01:1; ...
 y=runge("f",x,[1,-10]); ...
 plot2d(x,y[1]):

Instable Solutions of Differential Equations

The exakt solution is

Instable Solutions of Differential Equations

However, the equation has a second solution exp(10*x). The general solution is the following.

>&ode2('diff(y,x,2)=100*y,y,x)
                              10 x        - 10 x
                     y = %k1 E     + %k2 E

Even the difference to the true solution is very stable, and gets better with larger x.

>plot2d(x,y[1]-exp(-10*x)):

Instable Solutions of Differential Equations

But, if we iterate long enough, the runge algorithm will fork into the second solution (with a negative constant %k2).

>x=0:0.01:4; ...
 y=runge("f",x,[1,-10]); ...
 plot2d(x,y[1]):

Instable Solutions of Differential Equations

The adaptive Runge method does not help. The behavior is sort of random.

>x=0:0.01:4; ...
 y=adaptiverunge("f",x,[1,-10]); ...
 plot2d(x,y[1]):

Instable Solutions of Differential Equations

Our equation is simply

Instable Solutions of Differential Equations

with the following matrix A.

>A = [0,1;100,0]
            0             1 
          100             0 

The simple Euler method is

Instable Solutions of Differential Equations

>y=sequence("(id(2)+0.01*A).x[:,n-1]",[1;-10],401);
>x=0:0.01:4; plot2d(x,y[1]):

Instable Solutions of Differential Equations

The problem is the Eigenvalue 1.1 of the iteration matrix.

>real(eigenvalues(id(2)+0.01*A))
[1.1,  0.9]

We can try to fix this instability in this simple, linear case in the following way.

We use an implicit equation instead with

Instable Solutions of Differential Equations

In our simple case y'=A*y with a 2x2 matrix A, we get

Instable Solutions of Differential Equations

Thus we solve a linear system in each step.

>B=inv(id(2)-0.01*A/2).(id(2)+0.01*A/2); real(eigenvalues(B))
[1.10526,  0.904762]
>y=sequence("B.x[:,n-1]",[1;-10],401);

But this algorithm does not help either.

>x=0:0.01:4; plot2d(x,y[1]):

Instable Solutions of Differential Equations

Not even the LSODA algorithm works in this case, since the problem is just the instability of the initial condition. The stiff solvers only make sure that the part which is tending to 0 does indeed tend to 0. In our case, this is not the problem.

>x=0:0.01:4; ...
 y=ode("f",x,[1,-10]); ...
 plot2d(x,y[1]):

Instable Solutions of Differential Equations

Examples